using Digitalmes.Application.Mes.Productions.MaterialLoadings.Commands;
using Digitalmes.Application.Mes.Productions.MaterialLoadings.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Productions;

/// <summary>
/// 批次料上料记录终结点。
/// </summary>
public sealed class BatchMaterialLoadingEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/production", "batchMaterialLoading")
            .RequireAuthorization()
            .MapGet(GetBatchMaterialLoadingPagedListAsync, "list-page")
            .MapPut(UnloadBatchMaterialLoadingAsync, "unload");
    }

    [EndpointDescription("分页获取批次料上料记录")]
    public async Task<IApiResult> GetBatchMaterialLoadingPagedListAsync(ISender sender, [AsParameters] GetBatchMaterialLoadingListWithPagedQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("下料批次料")]
    public async Task<IApiResult> UnloadBatchMaterialLoadingAsync(ISender sender, UnloadBatchMaterialLoadingCommand command)
    {
        var result = await sender.Send(command);
        return result.ToApiResult();
    }
}
